#{extends 'backend_main.html' /}
    <div class="x-body">
        <form class="layui-form">
            <input type="hidden" id="id" name="id" value="${sysUser?.id}">
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span>登录名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="username" name="username" required="" lay-verify="required|username" autocomplete="off" class="layui-input" value="${sysUser?.username}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>将会成为您唯一的登入名
              </div>
          </div>
          <div class="layui-form-item">
              <label for="mobile" class="layui-form-label">
                  <span class="x-red">*</span>手机
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="mobile" name="mobile" required="" lay-verify="mobile" autocomplete="off" class="layui-input" value="${sysUser?.mobile}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>将会成为您唯一的登入名
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label"><span class="x-red">*</span>角色</label>
              <div class="layui-input-block">
              #{list sysRoleList}
                <input type="checkbox" name="chkRoles" lay-skin="primary" title="${_?.role_name}" value="${_?.id}">
              #{/list}
              </div>
          </div>
          <div class="layui-form-item">
              <label for="password" class="layui-form-label">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="password" name="password" required="" lay-verify="password" autocomplete="off" class="layui-input" value="${sysUser?.password}">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  6到16个字符
              </div>
          </div>
            <div class="layui-form-item">
                <label for="common" class="layui-form-label">
                    <span class="x-red">*</span>备注
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="common" name="common" required="" lay-verify="common" autocomplete="off" class="layui-input" value="${sysUser?.common}">
                </div>
            </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  提交
              </button>
          </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
          //自定义验证规则
          form.verify({
              username: function(value){
              if(value.length < 2){
                return '名称至少得2个字符啊';
              }
            }
            ,password: [/(.+){6,12}$/, '密码必须6到12位']
          });
          //监听提交
          form.on('submit(add)', function(data){
              var chkValue = new Array();
              var obj = $(".layui-form-checked");
              obj.each(function () {
                 var tmp = $(this).prev("input").val();
                 chkValue.push(tmp);
              });
              $.ajax({
                  type:"POST", //请求类型
                  #{if initEdit}
                      url:"/SystemCenter/adminEdit?v=update&chkRoles=" + chkValue.toString(),                 //URL
                  #{/if}
                  #{else }
                      url:"/SystemCenter/adminEdit?v=insert&chkRoles=" + chkValue.toString(),                 //URL
                  #{/else}
                  data:data.field,                  //传递的参数
                  dataType:"json",                 //返回的数据类型
                  success:function(data){          //data就是返回的json类型的数据
                      layer.alert("提交成功", {icon: 6},function () {
                          parent.window.location.reload();
                      });
                  }
              });
              return false;
          });
          #{if initEdit && jsonRole!=''}
              var jsonRole = #{verbatim}${jsonStr}#{/verbatim}
              var obj = $(".layui-form-checkbox");
              obj.each(function () {
                  var chk0 = $(this);
                  var tmp = $(this).prev("input").val();
                  for (var i=0;i<jsonRole.length;i++){
                      var objjr = jsonRole[i];
                      if(tmp==objjr.role_id){
                          $(chk0).addClass('layui-form-checked');
                      }
                  }
              });
          #{/if}
        });
    </script>
